<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1,
			shrink-to-fit=no" name="viewport">
    <title>书友网首页</title>
    <link rel="stylesheet" href="./assets/css/app.min.css">
    <link rel="stylesheet" href="./assets/css/style.css">
    <link rel="stylesheet" href="./assets/css/components.css">
    <link rel="stylesheet" href="./assets/css/custom.css">
    <link rel='shortcut icon' type='image/x-icon' href='./assets/img/favicon.ico'/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        .el-tag + .el-tag {
            margin-left: 10px;
        }
        .button-new-tag {
            margin-left: 10px;
            height: 32px;
            line-height: 30px;
            padding-top: 0;
            padding-bottom: 0;
        }
        .input-new-tag {
            width: 90px;
            margin-left: 10px;
            vertical-align: bottom;
        }
    </style>
    <style>
        [v-cloak]{
            display: none;
        }
    </style>
</head>

<body>
<div id="indexVue" v-cloak>
    <!--<div class="loader"></div>-->
    <div id="app">

        <div class="main-wrapper main-wrapper-1">
            <div class="navbar-bg"></div>

            <user-cart :avatar="user.avatar" :account="user.account"></user-cart>
            <!-- 左侧菜单页 -->
            <div class="main-sidebar sidebar-style-2">
                <aside id="sidebar-wrapper">
                    <div class="sidebar-brand">
                        <a href="Index.html">
                            <img alt="image" src="./assets/img/logo.png" class="header-logo"/>
                            <span class="logo-name">书友网</span>
                        </a>
                    </div>
                    <div class="sidebar-user">
                        <div class="sidebar-user-picture">
                            <img alt="image" :src="user.avatar">
                        </div>
                        <div class="sidebar-user-details">
                            <div class="user-name">{{user.nickName}}</div>
                            <div class="user-role">{{user.account}}</div>
                        </div>
                    </div>
                    <el-menu background-color="#fff" text-color="#000" active-text-color="#409EFF" unique-opened
                             :collapse="isCollapse"
                             :collapse-transition="false"
                             :default-active="activePath">
                        <!-- 一级菜单 -->
                        <template  v-for="item in menuList">
                            <el-submenu v-if="item.children.length > 0" :index="item.id + ''" :key="item.id">
                                <!-- 一级菜单的模板区域 -->
                                <template slot="title">
                                    <i :class="item.icon"></i>
                                    <span>{{item.menuName}}</span>
                                </template>

                                <!-- 二级菜单 -->
                                <el-menu-item v-if="item.children" :index="subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState(subItem.path)">
                                    <template slot="title">
                                        <span>{{subItem.menuName}}</span>
                                    </template>
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else  :index="item.path" :key="item.id" @click="saveNavState(item.path)">
                                <!-- 一级菜单的模板区域 -->
                                <template slot="title">
                                    <i :class="item.icon"></i>
                                    <span>{{item.menuName}}</span>
                                </template>
                            </el-menu-item>
                        </template>

                    </el-menu>
                </aside>
            </div>
            <!-- Main Content -->
            <div class="main-content">
                <div class="col-12 col-sm-12 col-lg-12">
                    <h2 class="section-title">好友推荐</h2>
                    <p class="section-lead">
                        这里系统会根据你的信息采用相关算法匹配与您类似的好友.
                    </p>
                </div>
                <div class="row" style="margin-top: 10px">
                    <div v-for="(user,index) in userList" class="col-12 col-sm-12 col-lg-6" :key="index">
                        <div class="card author-box card-primary">
                            <div class="card-body" style="height: 210px;">
                                <div class="author-box-left">
                                    <img alt="image" :src="user.avatar" class="rounded-circle author-box-picture">
                                    <div class="clearfix"></div>
                                    <a href="#" @click="addUser(user.id)" class="btn btn-primary mt-3 follow-btn" data-follow-action="alert('follow clicked');"
                                       data-unfollow-action="alert('unfollow clicked');">添加好友</a>
                                </div>
                                <div class="author-box-details">

                                    <div class="author-box-name" style="margin-left: 10px">
                                        <a href="#">{{user.nickName}}</a>
                                    </div>
                                    <div class="author-box-job" style="margin-top: 10px"><el-tag size="mini" type="info">登录账号</el-tag><span style="margin-left: 20px">{{user.account}}</span></div>
                                    <div class="author-box-description">
                                        <p>个人签名：{{user.remark}}</p>
                                    </div>
                                    <div class="mb-2 mt-3">
                                        <div class="text-small font-weight-bold">加入日期: {{user.createTime  | formatDate}}</div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <my-footer></my-footer>
        </div>
    </div>
</div>
<el-dialog :visible.sync="dialogVisible">
    <img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>

<script src="./common/js/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="./compont/foot.js"></script>
<script src="./compont/UserCart.js"></script>
<script src="./common/js/common.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/2.3/layer.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<!-- General JS Scripts -->
<script src="./assets/js/app.min.js"></script>
<!-- JS Libraies -->
<!-- Page Specific JS File -->
<script src="./assets/js/page/index2.js"></script>
<script src="./assets/js/page/todo.js"></script>
<!-- Template JS File -->
<script src="./assets/js/scripts.js"></script>
<!-- Custom JS File -->
<script src="./assets/js/custom.js"></script>



<script>
    const vm = new Vue({
        el: "#indexVue",
        data: {
            userList:[],
            user :{
                avatar : '',
                nickName:'',
                userId:'',
                account:'',
            },
            // 左侧菜单数据
            menuList: [],
            // 是否折叠
            isCollapse: false,
            // 被激活的链接地址
            activePath: '',
        },
        created() {
            this.getMenuList()
            this.getUserInfoList()
            this.getUserRecommend();
            this.activePath = window.localStorage.getItem('activePath')
        },
        filters: {
            formatDate: function(value) {
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? "0" + MM : MM;
                let d = date.getDate();
                d = d < 10 ? "0" + d : d;
                let h = date.getHours();
                h = h < 10 ? "0" + h : h;
                let m = date.getMinutes();
                m = m < 10 ? "0" + m : m;
                let s = date.getSeconds();
                s = s < 10 ? "0" + s : s;
                return y + "-" + MM + "-" + d ;
            }
        },
        methods:{
            getUserInfoList(){
                var userId = localStorage.getItem("userId");
                var account = localStorage.getItem("account");
                var nickName = localStorage.getItem("nickName");
                var avatar = localStorage.getItem("avatar");
                this.user.account = account;
                this.user.userId = userId;
                this.user.nickName = nickName;
                this.user.avatar = avatar;
            },
            addUser(userId){
                const that = this;
                const data = {
                    toId : userId
                }
                HttpPost("/friends/saveFriend",data,function (res) {
                    if (res.result == true){
                        layer.msg("添加成功",{icon:1},function(){
                            that.getUserAll();
                        });
                    }else{
                        layer.msg("添加失败",{icon:2});
                    }
                })
            },
            getUserRecommend(){
                const  that = this;
                HttpGet("/user/getUserRecommend",null,function (res) {
                    if (res.result == true){
                        that.userList = res.data;
                    }else{
                        layer.msg(res.message,{icon:2,time:2000});
                    }
                })
            },

            getMenuList(){
                const that = this;
                HttpGet("/menu/getList",null,function (res) {
                    if (res.result == true){
                        that.menuList = res.data;
                    }else{
                        layer.msg("获取列表失败！请刷新重试~",{icon:2,time:2000})
                    }
                })
            },
            // 点击按钮，切换菜单的折叠与展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            // 保存链接的激活状态
            saveNavState(activePath) {
                window.localStorage.setItem('activePath', activePath)
                this.activePath = activePath
                window.location.href = activePath;
            }


        },
    })
</script>
</body>

</html>
